package com.jadefashion.controller;


import com.jadefashion.health.entity.QueryPageBean;
import com.jadefashion.health.entity.Result;
import com.jadefashion.health.resources.MessageConstant;
import com.jadefashion.pojo.CheckItem;
import com.jadefashion.service.CheckitemService;
import org.apache.dubbo.config.annotation.Reference;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;

import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;
import java.util.Map;

@RestController
@RequestMapping("checkitem")
public class CheckitemController {
    @Reference
    private CheckitemService checkitemService;

    @RequestMapping("findPage.do")
    @PreAuthorize("hasAuthority('CHECKITEM_QUERY')")
    public Object findPage(@RequestBody QueryPageBean queryPageBean){
        Result result= null;
        try {
            Map<String,Object> map= checkitemService.findPage(queryPageBean);
           result = new Result(true, MessageConstant.QUERY_CHECKITEM_SUCCESS,map);
        } catch (Exception e) {
            e.printStackTrace();
            result = new Result(false, MessageConstant.QUERY_CHECKITEM_FAIL);
        }
        return result;
    }

    @RequestMapping("addCheckitem.do")
    @PreAuthorize("hasAuthority('CHECKITEM_ADD')")
    public Object addCheckitem(@RequestBody CheckItem checkItem){
        try {
            checkitemService.addCheckitem(checkItem);
            return  new Result(true,MessageConstant.ADD_CHECKITEM_SUCCESS);
        } catch (Exception e) {
            return  new Result(true,MessageConstant.ADD_CHECKITEM_FAIL);
        }
    }
    @RequestMapping("updateCheckitemByCondition.do")
    @PreAuthorize("hasAuthority('CHECKITEM_EDIT')")
    public Object updateCheckitemByCondition(@RequestBody CheckItem checkItem){
        try {
            checkitemService.updateCheckitemByCondition(checkItem);
            return  new Result(true,MessageConstant.ADD_CHECKITEM_SUCCESS);
        } catch (Exception e) {
            return  new Result(true,MessageConstant.ADD_CHECKITEM_FAIL);
        }
    }

    @RequestMapping("deleteCheckitemById.do")
    @PreAuthorize("hasAuthority('CHECKITEM_DELETE')")
    public Object deleteCheckitemById(@RequestParam("id") Integer id){
        try {
            checkitemService.deleteCheckitemById(id);
            return new Result(true,MessageConstant.DELETE_CHECKITEM_SUCCESS);
        } catch (Exception e) {
            return new Result(true,MessageConstant.DELETE_CHECKITEM_FAIL);
        }
    }

    @RequestMapping("findAll.do")
    @PreAuthorize("hasAuthority('CHECKITEM_QUERY')")
    public Object findAll(){
        Result result= null;
        try {
            List<CheckItem> list= checkitemService.findAll();
            result = new Result(true, MessageConstant.QUERY_CHECKITEM_SUCCESS,list);
        } catch (Exception e) {
            result = new Result(false, MessageConstant.QUERY_CHECKITEM_FAIL);
        }
        return result;
    }
}
